const db = wx.cloud.database();
Page({
  options: {
    addGlobalClass: true,
  },
  data: {
    avatarUrl: '',
    userInfo: {},
    userName: 'null',
    userClass: 'null',
    elements: [{
        id: '0',
        title: '测试',
        name: 'answer',
        icon: 'question',
        color: 'blue'
      },{
        id: '1',
        title: '预约',
        name: 'order',
        icon: 'like',
        color: 'red'
      },{
        id: '2',
        title: '练习',
        name: 'exercise',
        icon: 'copy',
        color: 'cyan'
      },{
        id: '3',
        title: '错题',
        name: 'mistakes',
        icon: 'settings',
        color: 'pink'
      },
    ]
  },

  onLoad: function(options) {
    db.collection('userInfo').get({
      success: res => {
        console.log(res)
        this.setData({
          userInfo: res.data[0].userInfo,
          avatarUrl: res.data[0].avatarUrl,
          userName: res.data[0].name,
          userClass: res.data[0]._class,
        })
      }
    })
  },
  goMenu: function (e) {
    switch (1 * e.currentTarget.dataset.id) {
      case 0:
        wx.navigateTo({
          url: '../examhome/examhome?exam=002',
        })
        break;
      case 1:
        wx.navigateTo({
          url: '../order/order',
        })
        break;
      case 2:
        wx.navigateTo({
          url: '../moni/moni?exam=002',
        })
        break;
      case 3:
        wx.navigateTo({
          url: '../home/home?exam=002',
        })
        break;

    }
  },
})